<?php
/**
 * Created by XM·Tan.
 * Motto: Who shuts love out, in turn shall be shut out from love.
 * Date: 2021/3/22 18:19
 */

namespace app\admin\controller;


use app\admin\middleware\Auth;
use app\BaseController;
use app\common\lib\Show;
use app\common\lib\Status;
use think\exception\HttpResponseException;
use think\facade\Request;

class AdminBase extends BaseController {

    protected $middleware = [Auth::class];

    public $adminUser = null;
    protected function initialize() {
        parent::initialize(); // TODO: Change the autogenerated stub
        $this->adminUser = session(config('admin.session_admin'));
    }


    /**
     * 判断是否登录
     * @return bool
     */
    public function isLogin() {
        $this->adminUser = session(config('admin.session_admin'));
        if (empty($this->adminUser)) {
            return false;
        }
        return true;
    }

    public function redirect(...$args) {
        throw new HttpResponseException(redirect(...$args));
    }

    /**
     * 状态 /  删除
     * @return \think\response\Json
     */
    public function status() {
        $id = input('param.id', 0, 'intval');
        $status = input('param.status', 0, 'intval');
        if (!$id || !in_array($status, Status::getTableStatus())) {
            return Show::error('参数错误');
        }
        $res = $this->business->setFiledToValue($id, $status, 'status');
        if ($res) {
            return Show::success();
        } else {
            return Show::error();
        }
    }

}